<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
      <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
    <div id="app">
        <el-row style="float: left;">
    
            <el-button type="primary" @click="open1">返回</el-button>
    
          </el-row>
        <el-form ref="form" :model="form" label-width="80px" style="padding-top: 70px;margin-top: 50px;">
            <el-form-item label="频道编号">
              <el-input v-model="form.channelNumber"></el-input>
            </el-form-item>
            <el-form-item label="频道名字">
                <el-input v-model="form.channelName"></el-input>
            </el-form-item>
            <el-form-item label="频道状态">
                <el-select v-model="form.channelStatus" placeholder="请选择是否禁用">
                  <el-option label="禁用" value="0"></el-option>
                  <el-option label="启用" value="1"></el-option>
                </el-select>
              </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">立即更改</el-button>
              <el-button @click="open1">取消</el-button>
            </el-form-item>
          </el-form>

    </div>
</body>
  <!-- import Vue before Element -->
  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../../data/axios-0.18.0.js"></script>
  <script>
    new Vue({
        el: '#app',
        data() {
          return {
            form: {
                id:'',
                channelName: '',
                channelStatus: '',
                channelNumber: ''
            }
          }
        },
        created(){
            this.init()
        },
        methods: {
          onSubmit() {
              console.log(JSON.stringify(this.form));
              axios({
                  method: "put",
                  url: "/channel",
                  data: JSON.stringify(this.form),
                  headers: {
                      'Content-Type': 'application/json;charset=UTF-8'
                  }
              }).then(resp => {
                  if (resp.data.code == 1){
                      this.$message.success("修改成功")
                  }else {
                      this.$message.error(resp.data.msg)
                  }
              })

          },
          open1(){
            location.href="../channel.html"
          },
          init(){
              var id  = window.localStorage.getItem('editId')
              window.localStorage.removeItem('editId')
              axios({
                  method: "get",
                  url: "/channel/"+id
              }).then(res=>{
                  console.log(res.data.data)
                  // res.data.data = res.data.data.channelStatus == 0 ? "禁用" : "启用";
                  this.form=res.data.data
              })
          }
        }
    })
  </script>
</html>